/**
 * Created by hxsd on 2016/7/8.
 */

angular.module("mainApp").controller("beautifulMusicCtrl",function($scope,$http){
    $scope.page = 0;        // 用来保存当前请求的页码
    $scope.total = 1;       // 用来保存总页数
    $scope.allInformation = [];
    // 加载餐馆的方法
    $scope.getInformation = function () {
        $scope.page++;  // 页数++
        var url = "views/beautifulPic/picJson.json";
        $http.get(url)
            .success(function (response) {
                angular.forEach(response.information, function (info) {
                    $scope.allInformation.push(info);    // 将新数据追加到数组中
                });
                // 更新总页面数，基于API发送的值
                $scope.total = response.totalPages; // 示例数据中为30页
                // 广播事件，告诉无限滚动组件everything is done
                $scope.$broadcast("scroll.infiniteScrollComplete");
            })
            .error(function (err) {
                $scope.$broadcast("scroll.infiniteScrollComplete");
                console.log(err);
            });
    };
    $scope.getInformation();    // 加载时，从API加载第一页餐馆数据
});
